package com.nantong.common.core.enums.commonEnums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 通用状态枚举
 *
 * @author nantong
 */
@Getter
@AllArgsConstructor
public enum StatusEnum {

    /**
     * 关闭
     */
    DISABLE(0, "关闭"),

    /**
     * 开启
     */
    ENABLE(1, "开启");

    private final Integer code;
    private final String desc;

    /**
     * 根据code获取枚举
     *
     * @param code 状态码
     * @return 状态枚举
     */
    public static StatusEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (StatusEnum value : StatusEnum.values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return null;
    }
}
